package org.cnc.explain.importselector;

import org.jetbrains.annotations.NotNull;
import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.TransactionManagementConfigurationSelector;

import java.util.Map;

/**
 * <p></p>
 * org.cnc.spring.explain.importselector - EnableXxImportSelector
 * ImportSelector 主要用来批量的加载一些必要的Bean, 通过返回需要加载的bean/configuration-bean的全限定名列表, 告诉系统需要加载的 BeanDefinition
 * <p></p>
 * 比如常用的{@link EnableTransactionManagement}, 就是通过import{@link TransactionManagementConfigurationSelector} 加载一些必要的事务管理bean
 * <p>
 *
 * @author tony-is-coding
 * @date 2022/7/5 14:18
 */
public class EnableXxImportSelector implements ImportSelector {

	@Override
	@NotNull
	public String[] selectImports(AnnotationMetadata metadata) {
		System.out.println("invoke EnableXxImportSelector");
		Map<String, Object> enableXxAttrs = metadata.getAnnotationAttributes(EnableXx.class.getName());
		boolean useXxByBB = (boolean) enableXxAttrs.getOrDefault("useXxByBB", false);
		System.out.println(useXxByBB);
		return new String[]{EnableXxConfiguration.class.getName()};
	}
}
